//#include <QGuiApplication>
//#include <QQmlApplicationEngine>
//#include <qqmlengine.h>
//#include <qqmlcontext.h>
//#include <qqml.h>
//#include <QtQuick/qquickitem.h>
//#include <QtQuick/qquickview.h>
//#include <QFontDatabase>
//#include <QQmlContext>
//#include <QSettings>
//#include <QQuickStyle>
//#include <QIcon>


#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QSettings>
#include <QQuickStyle>
#include <QIcon>
#include <QFontDatabase>
#include <QtQuickControls2>
#include "qmlconncpp.h"
#include "../serialQuickCommon/globalobject.h"

qmlConnCpp qmlconncpp;


int main(int argc, char *argv[])
{
    GlobalObject::objectInit();

    qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));

    QGuiApplication::setApplicationName("Gallery");
    QGuiApplication::setOrganizationName("QtProject");
    QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

    //设置默认字体
    QFont font;
    font.setPixelSize(10);
    font.setFamily("Microsoft YaHei");
    app.setFont(font);

    QIcon::setThemeName("gallery");

#if defined(Q_OS_WIN32)
        QSettings settings;
        QString style = QQuickStyle::name();
        if (!style.isEmpty())
            settings.setValue("style", style);
        else
            QQuickStyle::setStyle(settings.value("style").toString());//该代码在嵌入式系统中出错
#elif defined(Q_OS_LINUX)



#endif


    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty("station", &station);
    engine.rootContext()->setContextProperty("qmlconncpp", &qmlconncpp);
    engine.rootContext()->setContextProperty("portlist", &portlist);
    engine.rootContext()->setContextProperty("devicelist",&(devicelist));
    engine.rootContext()->setContextProperty("hostlist",&(hostlist));
    engine.rootContext()->setContextProperty("codelist",&(codelist));

#if defined(Q_OS_WIN32)
    engine.rootContext()->setContextProperty("availableStyles", QQuickStyle::availableStyles());//该代码在嵌入式系统中出错
#elif defined(Q_OS_LINUX)



#endif

    engine.load(QUrl("qrc:/serialQuickDemo/gallery.qml"));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}


//int main(int argc, char *argv[])
//{

//    GlobalObject::objectInit();

//    qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));

//    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

//    QGuiApplication app(argc, argv);

//    //设置默认字体
//    QFont font;
//    font.setPixelSize(10);
//    font.setFamily("Microsoft YaHei");
//    app.setFont(font);


//    QIcon::setThemeName("gallery");

//    //qmlRegisterType<SerialPort>("an.qt.mySerialPort",1,0,"SerialPort");
//    //qmlRegisterType<SerialPortHelper>("an.qt.mySerialPortHelper",1,0,"SerialPortHelper");
//    //qRegisterMetaType<DeviceList>("DeviceList");
//    //qRegisterMetaType<QList<Device>>("QList<Device>");
//    //qmlRegisterType<Station>("an.qt.Station",1,0,"Station");

//    //调试出系统字体列表
////    QFontDatabase database;
////    foreach (const QString &family, database.families(QFontDatabase::SimplifiedChinese))
////    {
////        qDebug()<<family;
////    }

//    QSettings settings;
//    QString style = QQuickStyle::name();
//    if (!style.isEmpty())
//        settings.setValue("style", style);
//    else
//        QQuickStyle::setStyle(settings.value("style").toString());





//    QQmlApplicationEngine engine;
//    engine.rootContext()->setContextProperty("station", &station);
//    engine.rootContext()->setContextProperty("qmlconncpp", &qmlconncpp);
//    engine.rootContext()->setContextProperty("portlist", &portlist);
//    engine.rootContext()->setContextProperty("devicelist",&(devicelist));
//    engine.rootContext()->setContextProperty("hostlist",&(hostlist));
//    engine.rootContext()->setContextProperty("availableStyles", QQuickStyle::availableStyles());
//    engine.load(QUrl("qrc:/serialQuickDemo/gallery.qml"));
//    if (engine.rootObjects().isEmpty())
//        return -1;

////    const QUrl url(QStringLiteral("qrc:/serialQuickDemo/gallery.qml"));
////    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
////                     &app, [url](QObject *obj, const QUrl &objUrl) {
////        if (!obj && url == objUrl)
////            QCoreApplication::exit(-1);
////    }, Qt::QueuedConnection);
////    engine.load(url);

//    return app.exec();
//}
